package com.deyuanyun.pic.settings.controller.vo;

import com.deyuanyun.pic.common.util.StringUtils;
import com.deyuanyun.pic.settings.domain.prvlg.Menu;
import com.github.pagehelper.Page;

import java.util.ArrayList;
import java.util.List;

public class RoleMenuVO extends SettingsBaseVO<Menu> {

    // 父节点id
    private String parentId;
    // 角色名称
    private String name;
    // 角色编号
    private String code;
    // 访问路径
    private String url;
    // 访问路径
    private String imgUrl;
    // 是否授权：0，
    private String isAuth;
    // 访问层级
    private String idPath;

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getImgUrl() {
        return imgUrl;
    }

    public void setImgUrl(String imgUrl) {
        this.imgUrl = imgUrl;
    }

    public String getIsAuth() {
        return isAuth;
    }

    public void setIsAuth(String isAuth) {
        this.isAuth = isAuth;
    }

    public String getIdPath() {
        return idPath;
    }

    public void setIdPath(String idPath) {
        this.idPath = idPath;
    }

    @Override
    public void fromDomain(Menu domain) {

        // 父节点id
        this.parentId = domain.getParentId();
        // 角色名称
        this.name = domain.getName();
        // 角色编号
        this.code = domain.getCode();
        // 访问路径
        this.url = domain.getUrl();
        // 是否授权：0，
        this.isAuth = domain.getUpdateRemark();
        // 访问路径
        this.imgUrl = domain.getImgUrl();

        super.fromDomain(domain.getId(), domain.getCreateRemark());
    }

    public List<RoleMenuVO> fromDomainList(List<Menu> domainList) {
        List<RoleMenuVO> list = new ArrayList<RoleMenuVO>();
        for (Menu menu : domainList) {
            RoleMenuVO roleMenuVO = null;
            if (StringUtils.isNullEmpty(menu.getParentId())){
                roleMenuVO = new RoleMenuVO();
                roleMenuVO.setIdPath(menu.getId());
                roleMenuVO.fromDomain(menu);
            } else {
                for (RoleMenuVO roleMenuVOTemp : list) {
                    if (menu.getParentId().equals(roleMenuVOTemp.getId())){
                        roleMenuVO = new RoleMenuVO();
                        roleMenuVO.setIdPath(roleMenuVOTemp.getIdPath()+menu.getId());
                        roleMenuVO.fromDomain(menu);
                    }
                }
            }
            if (roleMenuVO != null) {
                list.add(roleMenuVO);
            }
        }
        return list;
    }
}